<template>
  <el-dialog
    title="批量设置词库模板部位"
    :visible.sync="visible"
    :destroy-on-close="true"
    width="400px"
    :before-close="handleClose"
  >
    <div class="dlg_wrap">
      <el-form class="rule-form" ref="form" inline :model="ruleForm">
        <el-form-item
          label="词库模板部位"
          prop="partModality"
          class="short-input">
          <el-select
            style="width:100%"
            size="small"
            v-model="ruleForm.templatePart"
            placeholder="请选择"
            clearable
            allow-create
            filterable
          >
            <el-option
              v-for="item in templatepartOptions"
              :key="item"
              :label="item"
              :value="item"
            ></el-option>
          </el-select>
          <!-- <el-input
            style="width:100%"
            size="small"
            v-model="ruleForm.partModality"></el-input> -->
        </el-form-item>
        <div class="form_tips">
          请确认，已选择<b class="fc_red">{{ids.length}}</b>
          个部位，批量设置词库模板部位
        </div></el-form
      >
    </div>
    <span
      slot="footer"
      class="dialog-footer"><el-button @click="visible = false">取消</el-button><el-button type="primary" @click="sendSet">提交</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { settemplatepart, getlistbytemplatepart } from '@/api/api.js'
export default {
  props: {
    dialogVisibleTemplatePart: {
      type: Boolean,
      default: false
    },
    hospitalCode: {
      type: String,
      default: ''
    },
    ids: {
      type: Array,
      default: () => []
    },
    dep: {
      type: String,
      default: ''
    },
    modality: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      ruleForm: {
        templatePart: ''
      },
      templatepartOptions: []
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.ruleForm.templatePart = ''
        this.getlistbytemplatepart()
      }
    }
  },
  computed: {
    visible: {
      get() {
        return this.dialogVisibleTemplatePart
      },
      set(val) {
        this.$emit('update:dialogVisibleTemplatePart', val)
      }
    }
  },
  methods: {
    sendSet() {
      const _ids = this.ids.map(item => item.id)
      const params = {
        hospitalCode: this.hospitalCode,
        ids: _ids,
        templatePart: this.ruleForm.templatePart.toString(),
        dep: this.dep,
        modality: this.modality
      }
      settemplatepart(params).then(res => {
        if (res) {
          this.$message.success(res.message || '设置成功')
          this.visible = false
          this.$emit('refresh')
        }
      })
    },
    getlistbytemplatepart() {
      /* 词库模板部位 */
      let params = {
        hospitalCode: this.hospitalCode
      }
      return new Promise(resolve => {
        getlistbytemplatepart(params).then((res) => {
          if (res.code === 10000) {
            this.templatepartOptions = res.content.list
            resolve(res)
          }
        })
      })
    },
    handleClose() {
      this.visible = false
    }
  }
}
</script>
<style></style>
